package com.graduation.books_borrow.Controller;

import com.graduation.books_borrow.Service.BooksBorrowService;
import com.graduation.books_borrow.ret.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class BooksBorrowController {

    @Autowired
    private BooksBorrowService booksBorrowService;

    @PostMapping("borrowBook")
    public R borrowBook(@RequestBody Map<String, String> map) {
        String bookId = map.get("bookId");
        String userId = map.get("userId");

        return booksBorrowService.borrowBook(userId, bookId);
    }

    @PostMapping("returnBook")
    public R returnBook(@RequestBody Map<String, String> map) {
        String bookId = map.get("bookId");
        String userId = map.get("userId");

        return booksBorrowService.returnBook(userId, bookId);
    }

}
